-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(hook-store): override Hook Gas limit and tokens balances with Tenderly Simulation Data #5039
Conversation
@yvesfracari is attempting to deploy a commit to the cow Team on Vercel. A member of the Team first needs to authorize it. |
apps/cowswap-frontend/src/modules/hooksStore/containers/HookDappContainer/index.tsx
Outdated
Show resolved
Hide resolved
apps/cowswap-frontend/src/modules/hooksStore/dapps/BuildHookApp/index.tsx
Outdated
Show resolved
Hide resolved
apps/cowswap-frontend/src/modules/hooksStore/hooks/useBalancesDiff.ts
Outdated
Show resolved
Hide resolved
apps/cowswap-frontend/src/modules/hooksStore/hooks/useBalancesDiff.ts
Outdated
Show resolved
Hide resolved
apps/cowswap-frontend/src/modules/hooksStore/hooks/useBalancesDiff.ts
Outdated
Show resolved
Hide resolved
apps/cowswap-frontend/src/modules/hooksStore/hooks/useBalancesDiff.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All is good rn besides the issue (edge-case) we decided to address later.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The description of this PR made me think the scope is smaller. I don't think the description and code changes maches. Most of this PR is about calculating the aggregated balance given the current user's balance and the result from the similation.
apps/cowswap-frontend/src/modules/combinedBalances/hooks/useTokensBalancesCombined.ts
Outdated
Show resolved
Hide resolved
apps/cowswap-frontend/src/modules/combinedBalances/hooks/useTokensBalancesCombined.ts
Outdated
Show resolved
Hide resolved
const { preHooks, postHooks } = useHooks() | ||
const preHookBalanceDiff = usePreHookBalanceDiff() | ||
|
||
const orderMockBalanceDiff = useMemo(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why mock?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the lack of documentation. This is used mainly when the swap isn't simulated (like if the user has only preHooks). I changed a bit the variable name and comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thanks
apps/cowswap-frontend/src/modules/hooksStore/hooks/useBalancesDiff.ts
Outdated
Show resolved
Hide resolved
return bigA.add(bigB).toString() | ||
} | ||
|
||
function mergeBalanceDiffs(first: BalancesDiff, second: BalancesDiff): BalancesDiff { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking the type of the BalancesDiff
I see is a structure to hold token balances. Having Diff
in its name feels a bit constraining cause you can use it for example to hold the current balances, etc.
I would drop the diff
from the name and would make the merging utilities more generic so they live not in the hookStore
but in a more central place. Or at least can be moved to a utility instead of being in a hook file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the main difference between this and a token balances is that it can be negative. Another difference between this and the token balances used on the rest of the app is the first key. Another difference is that the outer key of BalanceDiff
is the address
which the difference is related to while the BalanceState
of the rest of the app the outer key is the chainId
since it is always related to the connected account. For now, I don't see any other place on the app where we would store balances diff from addresses, so I think that there isn't too much gain of moving this to a utility for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, makes sense
result[address][token] = addBigNumberStrings(result[address][token], second[address][token]) | ||
} catch (error) { | ||
console.error(`Error adding balances for address ${address} and token ${token}:`, error) | ||
throw error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this logic very similar to the other one that would apply the diffs to the current balances?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that is similar, however is used for only one value instead of all of them and that is why I am not importing the function from there.
apps/cowswap-frontend/src/modules/hooksStore/hooks/useHooksStateWithSimulatedGas.ts
Outdated
Show resolved
Hide resolved
apps/cowswap-frontend/src/modules/tenderly/utils/generateSimulationData.ts
Outdated
Show resolved
Hide resolved
Thanks for the review @anxolin ! I tried to resolve / reply all your questions. About the PR size, sorry it was supposed to be two separated PRs but then it was requested to be merged and I forget to update the description. About the gas limit, I already faced some issues of hooks not being executed due to out of gas, but never when the gas was defined by the tenderly. About the 10%, I just keep an old logic that existed on other hooks. |
…e-it-with-tenderly-simulation
As discussed on the channel, I removed the buffer of the Tenderly simulation gas. |
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
d2b652d
to
1745ea6
Compare
This was due some commits with a wrong author, already fixed it. Please ignore it 😅 |
Changes LGTM. @fairlighteth, WDYT? :) |
@yvesfracari I think you have some lint issues: ![]() |
I want to merge this PR so we start to consolidate things. Any enhancement we can try to do iterativelly to not keep this one open for too long For this, I created this PR which applies the changes of this PR plus fixes the lint issues I posted above #5080 |
Summary
Using
gasUsed
data of Tenderly simulation (added on bff on this PR) to overridegasLimit
hook data.To Test
bff
server locally in this PR contextbff
Note: The PR is in draft until the balanceDiff PR is merged. But feel free to test it (only the diffs will have that context as well)